package Modelo;
import Conexion.Conexion;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SIS_ACCESO{
	private double ID;
	private double INSERTAR;
	private double MODIFICAR;
	private double ELIMINAR;
        private Conexion con = null;

	public SIS_ACCESO(){}


	public List<SIS_ACCESO> ACCEDER(String usr, String pass){
		try{String consulta = "select sp.ID, max(spr.INSERTAR) AS INSERTAR, max(spr.MODIFICAR) AS MODIFICAR, max(spr.ELIMINAR) AS ELIMINAR from BROKER.SIS_PROCESO sp, BROKER.SIS_PROCESO_ROLES spr, BROKER.SIS_ROLES sr, BROKER.SIS_PERFILES_ROLES sperr, BROKER.SIS_PERFILES sper, BROKER.RRH_CARGO_PERFIL rcp, BROKER.RHH_CARGO rc, BROKER.RHH_USUARIO rus where spr.ID_ROLES = sr.ID and spr.ID_PROCESO = sp.ID and sperr.ID_PERFILES = sper.ID and sperr.ID_ROLES = sr.ID and rcp.ID_CARGO = rc.ID and rcp.ID_PERFIL = sper.ID and rus.ID_CARGO = rc.ID and rus.USUARIO like('"+usr+"') and rus.PASSWORD like ('"+pass+"') GROUP BY(sp.ID);";
			ResultSet rs = con.EjecutarConsulta(consulta);
			return Cargar(rs);
                }
		catch(Exception e){
			e.printStackTrace();}
			return null;
	}

	public List<SIS_ACCESO> Cargar(ResultSet rs){
		try{
			List<SIS_ACCESO> lista = new ArrayList<SIS_ACCESO>();
			while(rs.next()){
				SIS_ACCESO objeto = new SIS_ACCESO();
				objeto.setID(rs.getDouble("ID"));
				objeto.setINSERTAR(rs.getDouble("INSERTAR"));
				objeto.setMODIFICAR(rs.getDouble("MODIFICAR"));
				objeto.setELIMINAR(rs.getDouble("ELIMINAR"));
				lista.add(objeto);
			}
			return lista;
		}
		catch(SQLException ex){
			ex.printStackTrace();
		return null;}
	}

    public double getID() {
        return ID;
    }

    public void setID(double ID) {
        this.ID = ID;
    }

    public double getINSERTAR() {
        return INSERTAR;
    }

    public void setINSERTAR(double INSERTAR) {
        this.INSERTAR = INSERTAR;
    }

    public double getMODIFICAR() {
        return MODIFICAR;
    }

    public void setMODIFICAR(double MODIFICAR) {
        this.MODIFICAR = MODIFICAR;
    }

    public double getELIMINAR() {
        return ELIMINAR;
    }

    public void setELIMINAR(double ELIMINAR) {
        this.ELIMINAR = ELIMINAR;
    }

    public Conexion getCon() {
        return con;
    }

    public void setCon(Conexion con) {
        this.con = con;
    }        
}